import { ref } from 'vue'
import type pageModal from '@/components/pageModal/pageModal.vue'
type CallBackFnClick = (data?: any) => void
function usePageModal(
  newCallBack?: CallBackFnClick,
  editCallBack?: CallBackFnClick
) {
  const modalRef = ref<InstanceType<typeof pageModal>>()
  // 点击新增事件
  function handleNewClick() {
    modalRef.value?.setModalVisible()
    if (newCallBack) newCallBack()
  }
  // 点击编辑事件
  function handleEditClick(itemData: any) {
    modalRef.value?.setModalVisible(false, itemData)
    // 编辑时触发的回调
    if (editCallBack) editCallBack(itemData)
  }
  return {
    modalRef,
    handleNewClick,
    handleEditClick
  }
}

export default usePageModal
